import { getCarglaneDetail } from '@/api/fixing/fixing'

export default {
  namespaced: true,
  state: {
    CarglaneList: [],
    CarglaneListOne: [],
    CarglaneListTwo: [],
    businessId: ''
  },
  mutations: {
    updataCarglane (state, val) {
      state.CarglaneListOne.forEach((item, index) => {
        if (index < 5) {
          item.sku = val.leftarr[index]
        }
      })
      state.CarglaneListTwo.forEach((item, index) => {
        if (index < 5) {
          item.sku = val.rightarr[index]
        }
      })
    },
    setgetCarglaneDetaildata (state, val) {
      state.CarglaneList = val
      // eslint-disable-next-line array-callback-return
      state.CarglaneList.map((item, index) => {
        const num = item.channelCode
        if (num.split('-')[1] <= 5) {
          state.CarglaneListOne.push(item)
        } else {
          state.CarglaneListTwo.push(item)
        }
      })
    },
    delgetCarglaneDetaildata (state) {
      console.log('del')
      state.CarglaneListOne = []
      state.CarglaneListTwo = []
    },
    setbusinessId (state, val) {
      state.businessId = val
      // console.log( state.businessId );
    }
  },
  actions: {
    async getCarglaneDetaildata (context, val) {
      const res = await getCarglaneDetail({
        innerCode: val
      })
      context.commit('setgetCarglaneDetaildata', res.data)
    }
  }
}
